package combine.order.impl.dao.ibatis;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import combine.utils.dao.ibatis.IBatisEntityDao;

import combine.order.model.DataBase;
import combine.order.model.OrderItem;

@Repository
public class OrderItemDaoIbatis extends IBatisEntityDao<OrderItem> {

	@Override
	public Object insert(Object o) throws SQLException {
		OrderItem item = (OrderItem) o;
		item.setTotalNumber(item.getSNumber() + item.getMNumber()
				+ item.getLNumber() + item.getXlNumber());
		DataBase.orderItems.add(item);
		return item;
	}
	
	@SuppressWarnings("unchecked")
	public List<OrderItem> findOrderItemByOrderId(long orderId)
			throws SQLException {
//		return getSqlMapClient()
//				.queryForList(
//						"combine.order.model.OrderItem.findOrderItemByOrderId",
//						orderId);
		List<OrderItem> items = new ArrayList<OrderItem>();
		for(OrderItem item : DataBase.orderItems) {
			if(orderId == item.getOrderId()) {
				items.add(item);
			}
		}
		return items;
		
	}

}
